<?php
class Admin_LoaiDaoTaoController extends Zend_Controller_Action
{
	public function init()
	{
	
	}
	public function indexAction()
	{
		$loaidaotaoMapper = Data_Model_LoaiDaoTaoMapper::getInstance();
		$loaidaotao = $loaidaotaoMapper->loaidaotaoList();
		$this->view->loaidaotao = $loaidaotao;
	
	}
	public function themAction()
	{
		$this->view->title = "Thêm Loại Đào Tạo";
		$formThem = new Admin_Form_LoaiDaoTaoForm();
		$formThem->setMethod('post');
		$formThem->setAction('/QLHV/public/admin/loaidaotao/them/');
		$formThem->addElement('submit','submit',array('label'=>'Thêm'));
		$this->view->form = $formThem;
		if($this->getRequest()->isPost())
		{
			if($formThem->isValid($_POST))
			{
				$data = $formThem->getValues();
	
				$loaidaotao = $data['loaidaotao'];
	
				$loaidaotaoMapper = Data_Model_LoaiDaoTaoMapper::getInstance();
	
				$loaidaotaoObj = new Data_Model_LoaiDaoTao();
				$loaidaotaoObj->setTenloaidt($loaidaotao);
	
				$loaidt = $loaidaotaoMapper->save($loaidaotaoObj);
				$this->_redirect('/admin/loaidaotao/index/');
			}
		}
	}
	public function capnhatAction()
	{
		$this->view->title = "Cập Nhật Loại Đào Tạo";
		$formCapnhat = new Admin_Form_LoaiDaoTaoForm();
		$formCapnhat->setMethod('post');
		$formCapnhat->setAction('/QLHV/public/admin/loaidaotao/capnhat/');
		$formCapnhat->addElement('hidden','MaLoaiDT');
		$formCapnhat->addElement('submit','submit',array('label'=>'Cập nhật'));
		$this->view->form = $formCapnhat;
		$loaidaotao_id = $this->getRequest()->getParam('id');
		$loaidaotaoMapper = Data_Model_LoaiDaoTaoMapper::getInstance();
		if($this->getRequest()->isPost())
		{
			if($formCapnhat->isValid($_POST))
			{
				$data = $formCapnhat->getValues();
	
				$maloaidt = $data['MaLoaiDT'];
				$loaidaotao = $data['loaidaotao'];
	
	
	
				$loaidaotaoObj = new Data_Model_LoaiDaoTao();
				$loaidaotaoObj->setId($maloaidt);
				$loaidaotaoObj->setTenloaidt($loaidaotao);
	
				$loaidt = $loaidaotaoMapper->save($loaidaotaoObj);
				$this->_redirect('/admin/loaidaotao/index/');
			}
		}
		else
		{
			$ldt = $loaidaotaoMapper->searchLoaiDaoTaoById($loaidaotao_id);
				
			$formCapnhat->getElement('MaLoaiDT')->setValue($ldt->getId());
			$formCapnhat->getElement('loaidaotao')->setValue($ldt->getTenloaidt());
		}
	}
	public function xoaAction()
	{
		$this->_helper->viewRenderer->setNoRender(true);
		$maloaidt = $this->getRequest()->getParam('id');
		$loaidaotaoMapper = Data_Model_LoaiDaoTaoMapper::getInstance();
		$loaidaotaoMapper->delete($maloaidt);
		$this->_redirect('/admin/loaidaotao/index');
	}
}